n = input()
list1 = input().split(" ")
list2 = input().split(" ")
flag = False
for i in list1:
    if list2.count(i) > 0:
        flag = True
        break
if flag:
    print(1)
else:
    print(0)
